<template>
	<view class="content">
		<view class="user">
			<!-- 底图 - 开始 -->
			<image class="user-header-image" :src="user_banner"></image>
			<!-- 底图 - 结束 -->

			<!-- 用户信息 - 开始 -->
			<view class="flex-between">
				<view class="user-info-box">
					<image class="user-avg" :src="user_avg"></image>
					<view class="user-info-right">
						<view class="user-nickname">{{ account }}</view>
						<view class="user-phone">
							{{ phone }}
						</view>
					</view>
				</view>
				<view class="login-out" @click="logout">
					退出登录
				</view>
			</view>
			<!-- 用户信息 - 结束 -->

			<!-- 列表菜单 - 开始 -->
			<view class="user-activity-menu">
				<view class="menu-item" @click="goPage('express')">
					<view class="left">
						<image class="menu-icon" src="../../static/icon/icon_coupon.png"></image>
						<view class="menu-name">我的快递</view>
					</view>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
				<view class="menu-item" @click="goPage('express')">
					<view class="left">
						<image class="menu-icon" src="../../static/icon/icon_order.png"></image>
						<view class="menu-name">我的订单</view>
					</view>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
				<view class="menu-item" @click="goPage('mine')">
					<view class="left">
						<image class="menu-icon" src="../../static/icon/icon_userinfo.png"></image>
						<view class="menu-name">个人资料</view>
					</view>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
				<view class="menu-item" @click="goPage('contact')">
					<view class="left">
						<image class="menu-icon" src="../../static/icon/icon_contact.png"></image>
						<view class="menu-name">联系我们</view>
					</view>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
				<view class="menu-item">
					<view class="left">
						<image class="menu-icon" src="../../static/icon/icon_about.png"></image>
						<view class="menu-name">当前版本</view>
					</view>
					<view class="menu-number">{{ version }}</view>
				</view>
			</view>
			<!-- 列表菜单 - 结束 -->
		</view>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :type="dialogType" cancelText="关闭" confirmText="确定" title="警告"
				:content="contentText"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				version: '1.0.0',
				user_banner: '../../static/index_banner.png',
				user_avg: '../../static/avatar.png',
				user_name: '轻院煮义',
				account: '',
				dialogType: 'warn',
				contentText: ''
			}
		},
		onLoad() {
			this.account = uni.getStorageSync('account')
			if (this.account === '') {
				this.logout()
			}
		},
		onShow() {
			this.account = uni.getStorageSync('account')
			if (this.account === '') {
				this.logout()
			}
		},
		methods: {
			/* 跳转页面 */
			goPage(pageName) {
				if (pageName === 'mine' || pageName === 'contact') {
					this.contentText = `当前功能正在开发中……`
					this.$refs.alertDialog.open()
				} else {
					uni.switchTab({
						url: '/pages/' + pageName + '/' + pageName
					})
				}
			},
			logout() {
				uni.setStorageSync('account', '')
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f2f2f2;
		height: calc(100vh - 95px);
		overflow: auto;

		.user-header-image {
			width: 100%;
		}
		.flex-between {
			background: #ffffff;
			padding: 30rpx;
			margin: -80rpx 20rpx 20rpx 20rpx;
			border-radius: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: relative;
		}
		.user-info-box {
			display: flex;
			align-items: center;

			.user-avg {
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;
			}

			.user-nickname {
				margin-left: 20rpx;
			}

			.user-phone {
				margin-left: 20rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
		.login-out {
			color: #03a9f4;
			cursor: pointer;
		}
		.user-recharge-wrapper {
			background: #ffffff;
			border-radius: 20rpx;
			padding: 30rpx;
			margin: 20rpx;

			.user-recharge-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20rpx;

				.recharge-info {
					.info-title {
						color: #333;
						font-size: 28rpx;
						font-weight: bold;
					}

					.info-content {
						color: #999;
						font-size: 24rpx;
					}
				}

				.recharge-button {
					// background: #ff4131;
					color: #333;
					padding: 10rpx 20rpx;
					font-size: 22rpx;
					border-radius: 50rpx;
					flex-shrink: 0;
					border: 1rpx solid #dadbde;
				}
			}

			.recharge-user-money {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
				font-size: 26rpx;
				color: #333;

				.recharge-money {
					font-weight: bold;
					font-size: 30rpx;
				}

				.recharge-money::first-letter {
					font-size: 22rpx;
				}
			}
		}

		.user-activity-menu {
			padding: 30rpx;
			margin: 20rpx;
			border-radius: 20rpx;
			background: #fff;

			.menu-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 60rpx;

				.left {
					display: flex;
					align-items: center;

					.menu-icon {
						width: 40rpx;
						height: 40rpx;
					}


					.menu-name {
						font-size: 28rpx;
						margin-left: 20rpx;
						color: #333;
					}
				}

				.menu-number {
					font-size: 30rpx;
					color: #666666;
					letter-spacing: 2rpx;
				}
			}

			.menu-item:first-child {
				margin-top: 0;
			}
		}
	}
</style>